package exercise;

/*
2.请定义一个交通工具(Vehicle)的类其中有:
属性： 速度(speed)、 体积(size)等，
方法：移动(move())、设置速度(setSpeed(int speed))、加速 speedUp()、减速 speedDown()等。
最后在测试类 Vehicle 中的 main()中实例化一个交通工具对象并通过方法给它初始化 speed,size 的值并且通过打印出来。
另外调用加速、减速的方法对速度进行改变
 */
public class ex2 {
}

class Vehicle {
    private int speed;
    private int size;

    public Vehicle() {
    }

    public Vehicle(int speed, int size) {
        this.speed = speed;
        this.size = size;
    }

    public void move() {
        System.out.println("移动");
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void speedUp() {
        if (speed + 10 <= 200) {
            this.speed += 10;
            System.out.println("加速10km/h");
        } else {
            System.out.println("加速:" + (200 - this.speed));
            this.speed = 200;
        }

    }

    public void speedDown() {
        this.speed -= 10;
    }

    /**
     * 获取
     *
     * @return speed
     */
    public int getSpeed() {
        return speed;
    }

    /**
     * 获取
     *
     * @return size
     */
    public int getSize() {
        return size;
    }

    /**
     * 设置
     *
     * @param size
     */
    public void setSize(int size) {
        this.size = size;
    }

    public String toString() {
        return "Vehicle{speed = " + speed + ", size = " + size + "}";
    }

    public static void main(String[] args) {
        Vehicle vehicle = new Vehicle();
        vehicle.setSpeed(100);
        vehicle.setSize(10);
        System.out.println("体积：" + vehicle.getSize() + " 速度：" + vehicle.getSpeed());
        vehicle.speedUp();//加速
        System.out.println("体积：" + vehicle.getSize() + " 速度：" + vehicle.getSpeed());
        vehicle.speedDown();//减速
        System.out.println("体积：" + vehicle.getSize() + " 速度：" + vehicle.getSpeed());
    }
}
